//
//  AddNoteView.m
//  geoNotes
//
//  Created by Administrator on 6/24/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "AddNoteView.h"


@implementation AddNoteView
@synthesize titleField;
@synthesize messageField;
@synthesize delegate;
@synthesize locationManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [titleField release];
    [messageField release];
    
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
}

- (void)viewDidUnload
{
    [self setTitleField:nil];
    [self setMessageField:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (void) viewWillAppear:(BOOL)animated {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    locationManager.delegate = self;
    NSLog(@"%@",@"start updating");
    [locationManager startUpdatingLocation];
}
-(void) viewWillDisappear:(BOOL)animated{
    [locationManager stopUpdatingLocation];
    [locationManager release];
    locationManager=nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    NSLog(@"new position: %@",[newLocation description]);
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"error: %@",[error description]);
}
- (IBAction)onSave:(id)sender {
    [self.delegate addNoteViewDidFinish:self withTitle:[titleField text] andMessage:[messageField text]];
}

- (IBAction)onCancel:(id)sender {
    [self.delegate addNoteViewDidFinishWithCancel];
}
@end
